package com.xfp.mapper;

import com.github.pagehelper.Page;
import com.xfp.anntation.AutoFill;
import com.xfp.enumclass.OperationClass;
import com.xfp.pojo.dto.VmDto;
import com.xfp.pojo.dto.VmPolicyListDto;
import com.xfp.pojo.dto.VmQueryDto;
import com.xfp.pojo.entity.Policy;
import com.xfp.pojo.entity.TimeAndUser;
import com.xfp.pojo.entity.Vm;
import com.xfp.pojo.vo.VmQueryVO;
import com.xfp.pojo.vo.newVmVo;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PutMapping;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface VmMapper {
    /**
     * 获取基础信息
     * @param dto
     * @return
     */
    Page<Vm> pageVm(VmQueryDto dto);

    /**
     * 新增售货机
     * @param vo
     */
    @AutoFill(OperationClass.INSERT)
    void insert(Vm vo);

    /**
     * 修改设备
     * @param skuId
     * @param dto
     */
    void updateVm(String skuId, VmDto dto);

    /**
     * 修改设备node
     * @param skuId
     * @param nodeId
     */
    @AutoFill(OperationClass.UPDATE)
    void updateVmNode(TimeAndUser tu,String skuId, String nodeId);

    /**
     * 查询售货机策略
     * @param dto
     * @return
     */
    @Select("select * from tb_policy")
    List<Policy> findVmPolicy(VmPolicyListDto dto);

    /**
     * 查询设备id
     */
    List<String> findVmIdList(List<String> list);

    /**
     * 获取策略的折扣数
     * @param policyId
     * @return
     */
    @Select("select discount from tb_policy where policy_id = #{policyId}")
    int finDiscount(Integer policyId);

    /**
     * 根据policyId查询policyName
     * @param policyId
     * @return
     */
    @Select("select policy_name from tb_policy where policy_id = #{policyId}")
    String findPolicyName(Integer policyId);

    /**
     * 根据设备号查询设备id
     */
    @Select("select id from tb_vending_machine where inner_code = #{innerCode}")
    Integer findVmIdByVmInnerCode(String innerCode);

    /**
     * 应用策略
     * @param innerCodeList
     * @param policyId
     * @param policyName
     * @param discount
     * @param createTime
     * @param updateTime
     * @param createUser
     * @param updateUser
     */
    void applyPolicy(List<String> innerCodeList,String vmId,  Integer policyId, String policyName, int discount, LocalDateTime createTime, LocalDateTime updateTime, Long createUser, Long updateUser);

    /**
     * 查询售货机最大容量
     * @param innerCode
     * @return
     */
    @Select("select * from tb_channel where inner_code = #{innerCode} limit 0,1")
    Integer findMaxCapacityIdByVmInnerCode(String innerCode);

    /**
     * 查看是批量修改的售货机是否已经存在有策略
     * @param innerCodeList
     * @return
     */
    void deletePolicyByInnerCodeList(List<String> innerCodeList);

    /**
     * 删除售货机的策略
     * @param innerCode
     */
    @Delete("delete from tb_vm_policy where inner_code = #{innerCode}")
    void deleteByIdInnerCode(Integer innerCode);
}
